package cn.mafangui.hotel.controller.worker;

import cn.mafangui.hotel.entity.Room;
import cn.mafangui.hotel.entity.RoomType;
import cn.mafangui.hotel.entity.echarsEntity.Pie;
import cn.mafangui.hotel.response.AjaxResult;
import cn.mafangui.hotel.response.ResponseTool;
import cn.mafangui.hotel.service.OrderService;
import cn.mafangui.hotel.service.RoomTypeService;
import cn.mafangui.hotel.utils.PropInfoConstant;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author: kalpa
 * @date: 2022/4/3
 * @version: 1.0
 * Description: 用于获取echars的数据
 */
@RestController
@RequestMapping(value = "op/echars")
public class EcharsController {
    @Autowired
    RoomTypeService roomTypeService;

    @Autowired
    OrderService orderService;

    @ApiOperation("房间类型饼图数据")
    @GetMapping("/pieFromRoomType")
    public AjaxResult pieFromRoomType(){
        List<RoomType> roomTypeList = roomTypeService.findAllTypeAndRoomNum();
        List<Pie> pieList = new ArrayList<>();
        Pie pie = null;
        for(RoomType roomType : roomTypeList){
            pie = new Pie();
            pie.setName(roomType.getRoomType());
            pie.setValue(roomType.getRest());
            pieList.add(pie);
        }
        return ResponseTool.success(pieList);
    }

    @ApiOperation("订单饼图数据")
    @GetMapping("/pieFromOrder")
    public AjaxResult pieFromOrder(){
        List<Pie> pieList = orderService.findAllOrderAndRoomType();
        return ResponseTool.success(pieList);
    }

    @ApiOperation("订单量条形图数据")
    @GetMapping("/axisFromOrder")
    public AjaxResult axisFromOrder(){
        List<String> months = Arrays.asList("01","02","03","04","05","06","07","08","09","10","11","12");
        List<Integer> valueList = Arrays.asList(0,0,0,0,0,0,0,0,0,0,0,0);
        List<Pie> pieList = orderService.statisticalOrderNumByMonth();
        for(Pie pie : pieList){
            int idx = months.indexOf(pie.getName());
            valueList.set(idx, pie.getValue());
        }
        return ResponseTool.success(valueList);
    }


}
